Filecoin implements a Alpha Beta Filter for estimating the Block Reward and the QA Network Power on the Sector Initial Pledge Calculations.
Current parameters are:
%load_ext autotime
%load_ext autoreload
%autoreload 2
time: 10.8 ms (started: 2021-09-19 00:10:26 +00:00)
# External depences
import pandas as pd
import numpy as np
import plotly.express as px
# Move path to parent folder
import sys
sys.path.insert(1, '../')
# Internal dependences
from filecoin_metrics.connection import get_connection, get_connection_string
from filecoin_metrics.metrics import *
time: 589 ms (started: 2021-09-19 00:10:26 +00:00)
conn_string = get_connection_string('../config/sentinel-conn-string.txt')
connection = get_connection(conn_string)
BASELINE_CROSSING = '2021-04-02 05:00+00'
time: 237 ms (started: 2021-09-19 00:10:26 +00:00)
QUERY = f"""
/*
Retrieve block reward & qa network power daily averages / stdevs for
- Measurements
- Position Estimates
- Velocity Estimates
*/
select
/* Timestamp */
date_trunc('HOUR', to_timestamp(height_to_unix(cr.height))) as timestamp,
/* Reward measurements & estimates */
avg(cr.new_reward::numeric / 10^18) as reward_avg,
stddev(cr.new_reward::numeric / 10^18) as reward_std,
avg(cr.new_reward_smoothed_position_estimate::numeric / (2^128 * 10^18)) as reward_position_avg, /* FIL */
stddev(cr.new_reward_smoothed_position_estimate::numeric / (2^128 * 10^18)) as reward_position_std, /* FIL */
avg(cr.new_reward_smoothed_velocity_estimate::numeric / (2^128 * 10^18)) as reward_velocity_avg, /* FIL per epoch */
stddev(cr.new_reward_smoothed_velocity_estimate::numeric / (2^128 * 10^18)) as reward_velocity_std, /* FIL per epoch */
/* Power measurements & estimates */
avg(cp.total_qa_bytes_power::numeric / 1024^5) as qa_power_avg, /* PiB */
stddev(cp.total_qa_bytes_power::numeric / 1024^5) as qa_power_std, /* PiB */
avg(cp.qa_smoothed_position_estimate::numeric / (2^128 * 1024^5)) as qa_power_position_avg, /* PiB */
stddev(cp.qa_smoothed_position_estimate::numeric / (2^128 * 1024^5)) as qa_power_position_std, /* PiB */
avg(cp.qa_smoothed_velocity_estimate::numeric / (2^128 * 1024^5)) as qa_power_velocity_avg, /* PiB per epoch */
stddev(cp.qa_smoothed_velocity_estimate::numeric / (2^128 * 1024^5)) as qa_power_velocity_std /* PiB per epoch */
FROM chain_rewards cr
join chain_powers cp on cp.height = cr.height
where cr.height > 148888 /* Mainnet Launch Block Height */
group by timestamp
order by timestamp
"""
query_df = (pd.read_sql(QUERY, connection))
time: 2.53 s (started: 2021-09-19 00:10:26 +00:00)
fig = px.line(query_df,
x='timestamp',
y=['reward_avg', 'reward_position_avg'],
title='Hourly Averages of Block Reward')
fig.show()
time: 1.08 s (started: 2021-09-19 00:10:29 +00:00)
fig = px.line(query_df,
x='timestamp',
y=['reward_std', 'reward_position_std'],
log_y=True,
title='Hourly Standard Deviation of Block Rewards')
fig.show()
time: 752 ms (started: 2021-09-19 00:10:30 +00:00)
velocity_z = (query_df.reward_velocity_std / query_df.reward_velocity_avg).abs()
fig = px.line(query_df.assign(std_per_avg=velocity_z),
x='timestamp',
y='std_per_avg',
log_y=True,
title='Block Reward Velocity Hourly Standard Score')
fig.show()
time: 398 ms (started: 2021-09-19 00:10:31 +00:00)
relative_error = (query_df.reward_avg - query_df.reward_position_avg) / query_df.reward_avg
df = query_df.assign(relative_reward_error=relative_error)
fig = px.line(df,
x='timestamp',
y='relative_reward_error',
title='Mean Relative Error on Hourly Averages of Block Rewards')
fig.update_layout(yaxis=dict(tickformat=".2%"))
fig.show()
time: 392 ms (started: 2021-09-19 00:10:31 +00:00)
fig = px.line(query_df,
x='timestamp',
y=['qa_power_avg', 'qa_power_position_avg'],
title='Hourly Averages of QA Power')
fig.show()
time: 766 ms (started: 2021-09-19 00:10:32 +00:00)
fig = px.line(query_df,
x='timestamp',
y=['qa_power_std', 'qa_power_position_std'],
log_y=True,
title='Hourly Standard Deviation of QA Power')
fig.show()
time: 869 ms (started: 2021-09-19 00:10:33 +00:00)
relative_error = (query_df.qa_power_avg - query_df.qa_power_position_avg) / query_df.qa_power_avg
df = query_df.assign(relative_reward_error=relative_error)
fig = px.line(df,
x='timestamp',
y='relative_reward_error',
title='Mean Relative Error on Hourly Averages of QA Power')
fig.update_layout(yaxis=dict(tickformat=".1%"))
fig.show()
time: 399 ms (started: 2021-09-19 00:10:33 +00:00)
velocity_z = (query_df.qa_power_velocity_std / query_df.qa_power_velocity_avg).abs()
fig = px.line(query_df.assign(std_per_avg=velocity_z),
x='timestamp',
y='std_per_avg',
log_y=True,
title='QA Power Velocity Hourly Standard Score')
fig.show()
time: 391 ms (started: 2021-09-19 00:10:34 +00:00)